//index.js
//获取应用实例
const app = getApp()
const APP_ID = '';//输入小程序appid  
const APP_SECRET = '';//输入小程序app_secret  
var OPEN_ID = ''//储存获取到openid  
var SESSION_KEY = ''//储存获取到session_key  

Page({
  data: {
    motto: 'Hello World',
    count:0,
    items:'',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  onReady: function () {
console.log("22423");
var that = this;
var url = app.globalData.showitem + `?openid=${app.globalData.openid}`;
wx.request({
  url: url,
  success: function (res) {
    that.setData({
      items: res.data
    })
  }
})
  },
  onLoad: function () {
  
  },
  order:function(e)
  {
    var that=this;
    var url=app.globalData.order+`?openid=${app.globalData.openid}`;
    wx.request({
      url: url,
      success:function(res)
      {
        that.setData({
          items:res.data
        })
      }
    })
  },
  showdetail:function(e){
    var url = '../detail/detail?name=' + e.currentTarget.id;
wx.navigateTo({
  url: url,
})
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    
  },
  search:function(e){
wx.navigateTo({
  url: '../search/search',
})
  },
  camera:function(e){
//调用二维码接口
    wx.scanCode({
      success: (res) => {
        console.log(res)
      }
    })
  },
  list:function(e){
    //实现一个简单列表
    var that=this;
    that.setData({
      count:that.data.count+1
    })

  },
  detail:function(e)
  {
    if(e.currentTarget.id=="手动添加")
    {
//跳转到手动添加
console.log("手动添加");
      console.log(app.globalData.test);
      wx.navigateTo({
        url: '../add/add',
      })
    }
    else if(e.currentTarget.id=="批量操作")
    {
//跳转到批量操作
      console.log("批量操作");
    }
    else if(e.currentTarget.id=="导入名片")
    {
//跳转到导入名片
      console.log("导入名片");
    }
    else if(e.currentTarget.id=="通知")
    {
//跳转到通知
      console.log("通知");

    }
    
  },
  getUserInfo: function(e) {
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
